/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simulation;

import java.awt.Color;
import java.awt.Graphics;

/**
 *
 * @author haoliang.donghl
 */
public class Instance {
    public static final int STATE_RUNNING = 2;
    public static final int STATE_INSTANCE = 1;
    public static final int STATE_NONE = 0;
    public Application app;
    protected Machine machine;
    protected int state;
    protected float load;

    public Instance (Application app, Machine machine){
        this.app = app;
        this.machine = machine;
        this.state = STATE_NONE;
    }

    public void setState(int state){
        this.state = state;
    }

    public Machine getMachine(){
        return machine;
    }

    public int getState(){
        return state;
    }

    public void updateLoad(){
        if (this.state == STATE_RUNNING){
            this.load = app.getLoad() / app.getRunningNum();
        }
    }

    public float getLoad(){
        return load;
    }

    public int paint(Graphics g, int i1, int i2, int i4){
        g.setColor(this.app.color);
        int l = (int)(800 * this.load);
        g.fillRect(i1, i2, l, i4);
        return l;
    }
}
